package cn.webrx;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Reg4 {
    public static void main(String[] args) {
        String str = """
                he77llo 18
                html002
                     java 22
                -5
                over
                """;
        //把字符串中的数据求和
        Pattern p = Pattern.compile("[0-9\\-]+"); //模式类
        System.out.println(str);
        //System.out.println("-----------------");
        //System.out.println(str.replaceAll(p.toString(),""));

        Matcher m = p.matcher(str);//匹配器类
        int sum = 0;
        while (m.find()) {
            sum += Integer.parseInt(m.group());
        }
        System.out.println(sum);

    }
}
